package ibmetp.mis.controller.user;

import ibmetp.mis.common.Constants;
import ibmetp.mis.common.Message;
import ibmetp.mis.service.UserService;
import ibmetp.mis.serviceImpl.UserServiceImpl;
import ibmetp.mis.vo.User;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import net.sf.json.JSONObject;
/**
 * 添加用户Servlet
 * @author LAN DABIN
 * @created 2011-10-1
 *
 */
public class UserAddServlet extends HttpServlet {

	@Override
	public void service(ServletRequest request, ServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding(Constants.ENCODING_UTF8);
		System.out.println("Call UserAddServlet...");
		
		//获取用户参数
		User user=new User();
		user.setUserNo(request.getParameter("userNo"));
		user.setUserName(request.getParameter("userName"));
		user.setEmail(request.getParameter("email"));
		user.setPwd(request.getParameter("pwd"));
		user.setDescript(request.getParameter("descript"));
		
		//添加用户
		UserService us=new UserServiceImpl();
		String result=us.addUser(user);
		
		//如果有返回消息，则将消息发回页面
		if(result!=null){		
			response.setCharacterEncoding(Constants.ENCODING_UTF8);
			response.getWriter().print(JSONObject.fromObject(new Message(result)));
		}
	}

	
}
